package com.vv.tools.modules.utils.domain.service.impl;

import com.vv.tools.modules.utils.domain.model.QccProgressBO;
import com.vv.tools.modules.utils.domain.model.QccRequestBO;
import com.vv.tools.modules.utils.domain.service.QccAsyncService;
import com.vv.tools.modules.utils.domain.service.QccService;

import jakarta.annotation.Resource;

import java.util.UUID;

import org.springframework.stereotype.Service;

/**
 * @author wen.li
 */
@Service
public class QccServiceImpl implements QccService {

    @Resource
    private QccAsyncService qccAsyncService;

    @Override
    public String getResult(QccRequestBO requestBO) {
        String requestId = UUID.randomUUID().toString();
        QccProgressBO progress = new QccProgressBO();
        progress.setRequestId(requestId);
        progress.setCookie(requestBO.getCookie());
        progress.setBatchData(requestBO.getBatchData());
        progress.setProgress(0);
        qccAsyncService.set(requestId, progress);
        qccAsyncService.run(requestId);
        return requestId;
    }

    @Override
    public QccProgressBO getProgress(String requestId) {
        return qccAsyncService.get(requestId);
    }

}
